package com.j.lemon.learn.basic.thread;

public class DeadLock {

    public static void main(String[] args) {
        Object o =new Object();
        Object o1 = new Object();
        Thread t1 = new Thread(() -> {
            synchronized (o){
                System.out.println(Thread.currentThread().getName()+"开始调用A方法");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o1) {
                    System.out.println(Thread.currentThread().getName() + "开始调用B方法");
                }
                System.out.println(Thread.currentThread().getName() + "调用B方法结束");

            }

        });
        Thread t2 = new Thread(() -> {
            synchronized (o1){
                System.out.println(Thread.currentThread().getName()+"开始调用B方法");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o) {
                    System.out.println(Thread.currentThread().getName() + "开始调用A方法");
                }
                System.out.println(Thread.currentThread().getName() + "调用A方法结束");
            }

        });
        t1.start();
        t2.start();
    }
}
